package com.jsgt.greekfire.ui.mine.coindetail.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.fhx.core.base.BaseAdapter
import com.fhx.core.base.BaseViewHolder
import com.fhx.core.utils.DateFormatUtil
import com.fhx.core.utils.PriceFormatUtil
import com.jsgt.greekfire.App
import com.jsgt.greekfire.R
import com.jsgt.greekfire.bean.BillBean

/**
 * 交易记录列表适配器
 * author fhx
 * create time 2020/4/28 10:25
 **/
class TradingRecordAdapter(private val coinName: String) : BaseAdapter<BillBean>() {
    inner class VH(itemView: View) : BaseViewHolder(itemView) {

        var ite_tv1: TextView = itemView.findViewById(R.id.ite_tv1)
        var ite_tv2: TextView = itemView.findViewById(R.id.ite_tv2)
        var ite_tv3: TextView = itemView.findViewById(R.id.ite_tv3)
        var ite_tv4: TextView = itemView.findViewById(R.id.ite_tv4)
        var ite_tv5: TextView = itemView.findViewById(R.id.ite_tv5)


        @SuppressLint("ResourceAsColor")
        fun bindData(bean: BillBean) {

//            when (bean.assetEvent) {
//                5 -> {
//                    when (bean.assetGuid) {
//                        "1" -> {
//                            ite_tv1.text = "GFC" + "转账"
//                        }
//                        "2" -> {
//                            ite_tv1.text = "USDT" + "转账"
//                        }
//                        "3" -> {
//                            ite_tv1.text = "GFT" + "转账"
//                        }
//                    }
//
//                }
//                6 -> {
//
//                    when (bean.assetGuid) {
//                        "1" -> {
//                            ite_tv1.text = "GFC" + "收款"
//                        }
//                        "2" -> {
//                            ite_tv1.text = "USDT" + "收款"
//                        }
//                        "3" -> {
//                            ite_tv1.text = "GFT" + "收款"
//                        }
//                    }
//
//                }
//            }

//            ite_tv1.text = "$coinName${getEventString(bean.assetEvent!!)} "
              ite_tv1.text=bean.assetEventStr

//            ite_tv2.text = DateFormatUtil.formatNew(bean.createTime, "MM月dd日 HH:mm")
              ite_tv2.text=bean.createTime;
            when(bean.direction){
                0->{    ite_tv3.setTextColor(ContextCompat.getColor(App.context,R.color.trading_EE655F))
                    ite_tv3.text = "-"+PriceFormatUtil.format(bean.assetAmt?.toDouble(),4)}
                1->{
                    ite_tv3.setTextColor(ContextCompat.getColor(App.context,R.color.trading_4DB872))
                    ite_tv3.text =  PriceFormatUtil.format(bean.assetAmt?.toDouble(),4)
                }
                else->{
                    ite_tv3.setTextColor(ContextCompat.getColor(App.context,R.color.benesis_block_C6272C))
                    ite_tv3.text =  PriceFormatUtil.format(bean.assetAmt?.toDouble(),4)
                }
            }
//            if (bean.assetAmt!!.toDouble() > 0) {
//                ite_tv3.setTextColor(ContextCompat.getColor(App.context,R.color.trading_4DB872))
//                ite_tv3.text =   bean.assetAmt.toString()
//            } else {
//                ite_tv3.setTextColor(ContextCompat.getColor(App.context,R.color.trading_EE655F))
//                ite_tv3.text = bean.assetAmt.toString()
//            }
//            if (bean.assetGuid == "2") {
//
//                when (bean.assetEvent) {
//                    2 -> {
//                        ite_tv4.text = "手续费：" + "0.1"
//
//                    }
//                }
//            }
            ite_tv4.text = ""

            ite_tv5.text = "余额" + bean.assetAfter.toString()


//            when (bean.assetEvent) {
//                5 -> record_content_tv?.text = "转账${bean.assetAmt} $coinName"
//                6 -> record_content_tv?.text = "收款${bean.assetAmt} $coinName"
//            }
//            if (TextUtils.isEmpty(bean.userWallet?.walletName)) {
//                record_name_tv?.visibility = View.INVISIBLE
//                record_address_tv?.visibility = View.GONE
//            } else {
//                record_name_tv?.text = "钱包名称：" + bean.userWallet?.walletName
//                record_address_tv?.text = bean.userWallet?.utiAddress
//                record_name_tv?.visibility = View.VISIBLE
//                record_address_tv?.visibility = View.VISIBLE
//            }
//
//            if (bean.block == null) {
//                record_high_tv?.visibility = View.GONE
//                record_node_tv?.visibility = View.GONE
//            } else {
//                record_node_tv?.text = "" + bean.block?.node
//                record_high_tv?.text = "区块高度：${bean.block?.higth}"
//                record_high_tv?.visibility = View.VISIBLE
//                record_node_tv?.visibility = View.VISIBLE
//            }
//            record_time_tv?.text =
//                DateFormatUtil.formatNew(bean.createTime, "MM月dd日 HH:mm")
        }
    }

    override fun provideViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder? {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_trading_record, parent, false)
        return VH(view)
    }

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        val viewHolder = holder as VH
        viewHolder.bindData(dataList()[position])
    }


    private fun getEventString(event: Int): String {
        //1 充币  2 提现 3 买入 4 卖出 5 转账 6 收款 11 抢购
        return when (event) {
            1 -> "充币"
            2 -> "提现"
            3 -> "买入"
            4 -> "卖出"
            5 -> "转账"
            6 -> "收款"
            11 -> "抢购"
            else -> " "
        }
    }
}